package com.yfree.libs.letterscroll.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;

import com.yfree.R;
import com.yfree.libs.letterscroll.entity.LetterViewItemEntity;
import com.yfree.libs.letterscroll.main.LetterView;

import java.util.ArrayList;

public class LetterScrollView<T extends LetterViewItemEntity> extends
        LinearLayout {
    public LetterView<T> letterView;
    private Context context;

    public LetterScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        addView(LayoutInflater.from(context).inflate(
                R.layout.letterscroll_main, null));
    }

    public LetterScrollView(Context context) {
        super(context);
        this.context = context;
        addView(LayoutInflater.from(context).inflate(
                R.layout.letterscroll_main, null));
    }

    public void setEntityList(ArrayList<T> SourceDateList) {
        letterView = new LetterView<T>(context, this);
        letterView.init(SourceDateList);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        if (letterView != null) {
            letterView.setOnItemClickListener(onItemClickListener);
        } else {
            setEntityList(new ArrayList<T>());
        }
    }
}
